<template>
    <div>
        <el-dialog :title="dialogInfo.isAdd ? '添加轮播图' : '编辑会员'" :visible.sync="dialogInfo.isShow" :before-close="cancel"
            center>
            <el-form :model="memberInfo" :rules="rules" ref="memberInfo">
                <el-form-item label="手机号" :label-width="formLabelWidth" prop="phone">
                    <el-input v-model="memberInfo.phone" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="昵称" :label-width="formLabelWidth" prop="nickname">
                    <el-input v-model="memberInfo.nickname" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="密码" :label-width="formLabelWidth" prop="password">
                    <el-input v-model="memberInfo.password" autocomplete="off"></el-input>
                </el-form-item>
                <p>留空则不修改</p>
                <el-form-item label="状态" :label-width="formLabelWidth">
                    <el-switch v-model="memberInfo.status" active-color="#13ce66" inactive-color="#ff4949"
                        :active-value="1" :inactive-value="2">
                    </el-switch>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="cancel">取 消</el-button>
                <el-button type="primary" @click="comfirm">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { memberinfo, memberdit } from '../../request/api'
import { mapActions, mapGetters } from "vuex";
export default {
    props: ['dialogInfo'],
    data() {
        return {
            memberInfo: {
                nickname: '',
                phone: '',
                password: '',
                status: 1
            },
            formLabelWidth: "120px",
            rules: {
                nickname: [
                    { required: true, message: "请输入昵称", trigger: "blur" },
                    {
                        min: 2,
                        max: 8,
                        message: "长度在 2 到 8 个字符",
                        trigger: "blur",
                    },
                ],
                password: [
                    { required: true, message: "请输入密码", trigger: "change" },
                ],
                phone: [
                    { required: true, message: "请输入手机号", trigger: "change" },
                ]
            },
        };
    },
    computed: {
        ...mapGetters({
            memberList: 'member/getMember'
        })
    },
    mounted() {
        this.getMember()
    },
    methods: {
        ...mapActions({
            getMember: 'member/getMemberAction'
        }),
        cancel() {
            this.$emit('cancel', false)
            this.reset()
        },
        reset() {
            this.memberInfo = {
                nickname: '',
                phone: '',
                password: '',
                status: 1
            },
                //清空表单验证
                this.$refs.memberInfo.resetFields();
        },
        lookup(uid) {
            memberinfo({ uid }).then((res) => {
                if (res.data.code == 200) {
                    this.memberInfo = res.data.list;
                    this.memberInfo.uid = uid;
                    // 注意： 为空则不做修改！！！
                    this.memberInfo.password = ''
                }
            })
        },
        comfirm() {
            memberdit(this.memberInfo).then((res) => {
                if (res.data.code == 200) {
                    this.$message.success(res.data.msg);
                    //关闭弹框
                    this.cancel();
                    //重新获取列表
                    this.getMember()
                }else{
                    this.$message.error(res.data.msg);
                }
            })
        }

    }
};
</script>

<style scoped>
</style>
